import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../pages/Home'
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Test from '@/pages/Test'

Vue.use(VueRouter)

// 1保存原始push
const originPush = VueRouter.prototype.push;
//2VueRouter.prototype.push做增强
VueRouter.prototype.push = function (location, okCallback, errCallback) {
 //若使用push的人。没有传成功/失败的回调
 if (okCallback === undefined && errCallback === undefined) {
 // 调用最原始的push，把location放进去，放catch防止报错
 return originPush.call(this, location).catch(() => {});
 } else {
 // 若是传了，把它的给放在这里
 return originPush.call(this, location, okCallback, errCallback);
 }
};



const router =new VueRouter({
    mode:'history',
    routes:[
        {path:'/home',component:Home},
        {path:'/login',component:Login},
        {path:'/register',component:Register},
        {path:'/search',component:Search},
        {path:'/test',component:Test},
        {path:'/',redirect:'/home'}

    ]
})

export default router